﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace TFSTools.TFSLibrary
{
    public class TFSQueryParameter
    {
        public TFSQueryParameter()
        {
        }

        public TFSQueryParameter(TFSWorkItemType workItemType)
        {
            this.FieldName = "Work Item Type";
            this.StandardOperator = QueryOperators.Equals;
            this.ValueString = workItemType.Name;
        }

        public string FieldName { get; set; }

        public QueryOperators StandardOperator { get; set; }

        public string CustomOperator { get; set; }

        public string Operator
        {
            get
            {
                switch (this.StandardOperator)
                {
                    case QueryOperators.Equals:
                        return " = ";
                    case QueryOperators.DoesNotEqual:
                        return " <> ";
                    case QueryOperators.GreaterThan:
                        return " > ";
                    case QueryOperators.LessThan:
                        return " < ";
                    case QueryOperators.GreaterThanOrEqual:
                        return " >= ";
                    case QueryOperators.LessThanOrEqual:
                        return " <= ";
                    case QueryOperators.Contains:
                        return " Contains ";
                }

                return " " + this.CustomOperator.Trim() + " ";
            }
        }

        public string ValueString { get; set; }

        public int ValueInt32 { get; set; }
    }

    public class TFSQueryParameterCollection : Collection<TFSQueryParameter>
    {
        public TFSQueryParameterCollection() : base() { }

        public TFSQueryParameterCollection(IList<TFSQueryParameter> list) : base(list) { }
    }

    public enum QueryOperators
    {
        Custom,
        Equals,
        DoesNotEqual,
        GreaterThan,
        LessThan,
        GreaterThanOrEqual,
        LessThanOrEqual,
        Contains,
    }
}
